<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<style>
    #treeDiv {
        height: 100%;
        overflow-x: auto;
    }


</style>
<SCRIPT type="text/javascript">
    $(function () {
        var nodes = ${menuList}
        var setting = {
            treeId: 'menuTree',
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "parentId",
                    rootPid: 0
                }
            },
            callback: {
                beforeRename: beforeRename,       //输入名称后保存之前的回调
                onRename: onRename				 //修改后的回调
            },
            edit: {
                editNameSelectAll: true,
                enable: true,
                showRenameBtn: true,
                renameTitle: "编辑"
            }
        };


        $.fn.zTree.init($.CurrentNavtab.find("#menuTree"), setting, nodes);
        var treeObj = $.fn.zTree.getZTreeObj("menuTree");


        function beforeRename(treeId, treeNode, newName, isCancel) {
            if (newName.length == 0) {
                $(document).alertmsg('error', '节点名称不能为空', {
                    displayMode: 'slide',
                    displayPosition: 'topcenter',
                    okName: '好的',
                    title: '提示'
                });
                return false;
            }
            return true;
        }

        function onRename(event, treeId, treeNode, isCancel) {
            $(this).bjuiajax('doajax', {
                url: "menu/edit.shtml",
                type: "post",
                data: "id=" + treeNode.id + "&name=" + treeNode.name,
                callback: function (json) {
                    if (json.code == 0) {
                        $(document).alertmsg('ok', '修改成功', {
                            displayMode: 'slide',
                            displayPosition: 'topcenter',
                            okName: '好的',
                            title: '提示'
                        });
                    } else {
                        $(document).alertmsg('error', '修改失败', {
                            displayMode: 'slide',
                            displayPosition: 'topcenter',
                            okName: '好的',
                            title: '提示'
                        });
                    }
                }
            })
        }

    });
</SCRIPT>
<div class="bjui-pageContent">
    <div class="row" style="margin:0px;height:100%;width: 500px;">
        <div class="col-md-3" style="height:100%;width: 500px;">
            <div id="treeDiv" style="width: 300px;">
                <ul id="menuTree" class="ztree" style="width: 500px;"></ul>
            </div>
        </div>
    </div>
</div>